{php include wl_template('common/header');}
<ul class="nav nav-tabs">
	<li {if $_GPC['enabled']==1 }class="active"{/if}><a href="{php echo web_url('store/merchant/index',array('enabled'=>1));}">入驻中{if $status1}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status1}</span>{/if}</a></li>
	<li {if $_GPC['enabled']==6 }class="active"{/if}><a href="{php echo web_url('store/merchant/index',array('enabled'=>6));}">待入驻{if $status0}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status0}</span>{/if}</a></li>
	<li {if $_GPC['enabled']==2 }class="active"{/if}><a href="{php echo web_url('store/merchant/index',array('enabled'=>2));}">暂停中{if $status2}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status2}</span>{/if}</a></li>
	<li {if $_GPC['enabled']==3 }class="active"{/if}><a href="{php echo web_url('store/merchant/index',array('enabled'=>3));}">已到期{if $status3}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status3}</span>{/if}</a></li>
	<li {if $_GPC['enabled']==4 }class="active"{/if}><a href="{php echo web_url('store/merchant/index',array('enabled'=>4));}">垃圾箱{if $status4}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status4}</span>{/if}</a></li>
<!--	<li {if $_GPC['enabled']==5 }class="active"{/if}><a href="{php echo web_url('store/merchant/index',array('enabled'=>5));}">待审核{if $status5}<span class="label label-warning pull-right" style="margin-left: 10px;">{$status5}</span>{/if}</a></li>-->
</ul>
<div class="app-content">
	<div class="app-filter">
		<div class="alert alert-warning">
			商户登录地址：<a href="{$_W['siteroot']}web/citystore.php?p=user&ac=storelogin&do=store_login&i={$_W['uniacid']}" target="_blank">{$_W['siteroot']}web/citystore.php?p=user&ac=storelogin&do=store_login&i={$_W['uniacid']}</a>
		</div>
		<div class="filter-action">
			<a href="{php echo web_url('store/merchant/edit')}" class="btn btn-primary">添加商户</a>
		</div>
		<div class="filter-list">
			<form action="" method="get" class="form-horizontal" role="form" id="form1">
				<input type="hidden" name="c" value="site" />
				<input type="hidden" name="a" value="entry" />
				<input type="hidden" name="m" value="{MODULE_NAME}" />
				<input type="hidden" name="p" value="store" />
				<input type="hidden" name="ac" value="merchant" />
				<input type="hidden" name="do" value="index" />
				<input type="hidden" name="enabled" value="{$_GPC['enabled']}" />
				{if p('citydelivery')}
					<div class="form-group">
						<label class="col-sm-2 control-label">同城配送</label>
						<div class="col-sm-9">
							<div class="btn-group">
								<a href="{php echo web_url('store/merchant/index',['deliverystatus'=>0,'keywordtype'=>$_GPC['keywordtype'],'keyword'=>$_GPC['keyword'],'groupid'=>$_GPC['groupid']])}" class="btn {if $_GPC['deliverystatus'] == 0}btn-primary{else}btn-default{/if}">全部</a>
								<a href="{php echo web_url('store/merchant/index',['deliverystatus'=>1,'keywordtype'=>$_GPC['keywordtype'],'keyword'=>$_GPC['keyword'],'groupid'=>$_GPC['groupid']])}" class="btn {if $_GPC['deliverystatus'] == 1}btn-primary{else}btn-default{/if}">已开启</a>
								<a href="{php echo web_url('store/merchant/index',['deliverystatus'=>2,'keywordtype'=>$_GPC['keywordtype'],'keyword'=>$_GPC['keyword'],'groupid'=>$_GPC['groupid']])}" class="btn {if $_GPC['deliverystatus'] == 2}btn-primary{else}btn-default{/if}">未开启</a>
							</div>
						</div>
					</div>
				{/if}
				<div class="form-group form-inline">
					<label class="col-sm-2 control-label">搜索内容</label>
					<div class="col-sm-9">
						<select name="keywordtype" class="form-control">
							<option value="1" {if $_GPC['keywordtype']==1}selected="selected"{/if}>商户ID</option>
							<option value="2" {if $_GPC['keywordtype']==2}selected="selected"{/if}>商户名称</option>
							<option value="3" {if $_GPC['keywordtype']==3}selected="selected"{/if}>联系人名称</option>
							<option value="4" {if $_GPC['keywordtype']==4}selected="selected"{/if}>联系人电话</option>
						</select>
						<input type="text" name="keyword" class="form-control" value="{$_GPC['keyword']}"  placeholder="请输入关键字"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">商户套餐</label>
					<div class="col-sm-9">
						<select name="groupid" style="width: 100%;">
							<option value="">不限套餐</option>
							{loop $groups $group}
							<option value="{$group['id']}" {if $_GPC['groupid'] == $group['id']} selected="selected" {/if} >{$group['name']}</option>
							{/loop}
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">时间筛选</label>
					<div class="col-md-3">
						<select name="timetype" class="form-control">
							<option value="">请选择时间类型</option>
							<option value="1" {if $_GPC['timetype']==1}selected="selected"{/if}>入住时间</option>
							<option value="2" {if $_GPC['timetype']==2}selected="selected"{/if}>过期时间</option>
						</select>
					</div>
					<div class="col-md-2">
						{php echo tpl_select_time_info('time_limit', array('starttime' => date('Y-m-d H:i',$starttime), 'endtime' => date('Y-m-d H:i', $endtime)));}
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"></label>
					<div class="col-sm-9">
						<button class="btn btn-primary" id="search">搜索</button>
						<button class="btn btn-warning" type="submit" name="export" value="1">导出</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<div class="app-table-list">
		<div class="table-responsive">
			<table class="table table-hover">
				<thead>
					<tr>
						<th style="width: 30px;"><input type="checkbox" onclick="var ck = this.checked;$(':checkbox').each(function(){this.checked = ck});" /></th>
						<th>ID</th>
						<th style="width: 50px;">商户</th>
						<th></th>
						<th>账户余额</th>
						<th>店长</th>
						<th>店员</th>
						<th>所属套餐</th>
						<th>时间</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
				{loop $stores $user}
					<tr>
						<td><input type="checkbox" name="checkbox[]" class="checkbox" value="{$user['id']}" /></td>
						<td>{$user['id']}</td>
						<td class="text-left"><img class="scrollLoading" src="{IMAGE_PIXEL}" data-url="{php echo empty($user['logo']) ? IMAGE_NOPIC_SMALL : $user['logo'];}" height="50" width="50"/>
						</td>
						<td>
							<span style="display: inline-block;max-width: 200px;">{$user['storename']}</span>
							<span style="display: block;max-width: 200px;">{$user['mobile']}</span>
						</td>
						<td class="text-left">
							<label class="label label-warning">￥ {$user['nowmoney']}</label>
						</td>
						<td>
							{$user['realname']}
							<br>
							{$user['tel']}
						</td>
						<td>
							<a href="{php echo web_url('store/merchant/clerkindex',array('storeid'=>$user['id']))}">{$user['clerknum']}</a>
						</td>
						<td class="text-left">
							{if $user['groupname']}<label class="label label-success">{$user['groupname']}</label>{/if}
						</td>
						<td>
							入驻：{php echo date('Y-m-d',$user['createtime'])}<br>
							到期：{php echo date('Y-m-d',$user['endtime'])}
						</td>
						<td>
							{if $user['enabled']==0}<label class="label label-primary">待入驻</label>
							{elseif $user['enabled']==1}<label class="label label-success">入驻中</label>
							{elseif $user['enabled']==2}<label class="label label-warning">暂停中</label>
							{elseif $user['enabled']==3}<label class="label label-danger">已到期</label>
							{elseif $user['enabled']==4}<label class="label label-danger">可彻底删除</label>
							{/if}
						</td>
						<td style="position: relative;">
							<a class="btn btn-sm btn-default" href="{php echo web_url('store/merchant/edit',array('id'=>$user['id'],'page'=>$pindex))}">编辑</a>
                            {if $user['nowmoney'] > 0}
							<a class="btn btn-sm btn-default shopSettlement" href="javascript:;" sid="{$user['id']}" balance="{$user['nowmoney']}">结算</a>
                            {/if}
							<a class="btn btn-sm btn-default" href="{php echo web_url('store/merchant/storeQrCode',array('id'=>$user['id']))}" data-toggle="ajaxModal"><i class="fa fa-qrcode"></i></a>
							{if $user['enabled']!=4}
							<a class="btn btn-sm btn-default" href="{php echo web_url('store/merchant/delete',array('id'=>$user['id']))}" data-toggle="ajaxRemove" data-confirm="此操作会删除商家，造成商家商品不可用，确定要删除吗？">删除</a>
							{else}
							<a class="btn btn-sm btn-danger" href="{php echo web_url('store/merchant/sureDelete',array('id'=>$user['id']))}" data-toggle="ajaxRemove" data-confirm="此操作会彻底删除商家，不可恢复，确定要删除吗？">彻底删除</a>
							{/if}
						</td>
					</tr>
				{/loop}
				</tbody>
			</table>
		</div>
		<div class="app-table-foot clearfix">
			<div class="pull-left">
				<div id="de1" class="pull-left">
					<a href="javascript:;" class="btn btn-default min-width js-batch js-delete pass">删除商户</a>
				</div>
			</div>
			<div class="pull-right">
				{$pager}
			</div>
		</div>
	</div>
</div>
<script>
	var enabled = "{$_GPC['enabled']}";
	$('#de1').delegate('.pass','click',function(e){
		e.stopPropagation();
		var order_ids = [];
		var $checks=$('.checkbox:checkbox:checked');
		$checks.each(function() {
			if (this.checked) {
				order_ids.push(this.value);
			};
		});
		var $this = $(this);
		var ids = order_ids;
		util.nailConfirm(this, function(state) {
		if(!state) return;
			if(enabled == 4){
				var type = 2;
			}else{
				var type = 1;
			}
			$.post("{php echo web_url('store/merchant/deletes')}", { ids : ids ,type:type}, function(data){
				if(!data.errno){
				util.tips("删除成功！");
				location.reload();
				}else{
				util.tips(data.message);	
				};
			}, 'json');
		}, {html: '确认删除所选商户?',placement:'right'});
	});
	//商户申请结算
    $(".shopSettlement").on('click',function () {
        var sid = $(this).attr("sid");//获取店铺id
        var balance = $(this).attr("balance");//总余额
        tip.prompt('请输入提现金额,不能超过'+balance+'元！',function () {
            var money = $("[name='confirm']").val();//提现金额
            if(money > 0 && parseInt(balance) >= parseInt(money)){
                $.post("{php echo web_url('store/merchant/cash')}",{money:money,sid:sid},function (res) {
                    if(res.errno == 1){
                        tip.alert(res.message,function () {
                            history.go(0);
                        });
                    }else{
                        tip.alert(res.message);
                    }
                },'json');
            }else{
                tip.alert("请输入正确的提现金额");
            }
        });
    });
</script>
{php include wl_template('common/footer');}